package com.cdeledu.thread2.c4.threadlocal;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class Demo {

	private static final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

	public static class PaseDate implements Runnable{
		int i=0;
		public PaseDate(int i) {
			this.i= i;
		}
		@Override
		public void run() {
			try {
				Date t = sdf.parse("2015-03-29 19:29:"+i%60);
				System.out.println(i+":"+t);
			} catch (ParseException e) {
				e.printStackTrace();
			}
		}
	}

	//有可能会得到一些异常，因为SimpleDateFormat不是线程安全的，使用Demo2解决。
	public static void main(String[] args) {
		ExecutorService es = Executors.newFixedThreadPool(10);
		for(int i=0;i<1000;i++){
			es.execute(new PaseDate(i));
		}
	}

}
